<script lang="ts" setup>
import { UserFilled, Lock } from '@element-plus/icons-vue'
import { reactive, ref } from 'vue'
import { router } from '@/router'
import pinia from '@/store'
import { LoginParams } from '@/types/login'
import { useLoginStore } from '@/store/modules/login'
import { useUserStore } from '@/store/modules/user'

/**
 * 属性
 */
const title = ref('订单管理系统')
const loginStore = useLoginStore(pinia)
const userStore = useUserStore(pinia)
const loading = ref(false)
const form = reactive<LoginParams>({
  tenant: '',
  userName: '',
  userPassword: '',
})
/**
 * 函数
 */
const handleLogin = async (): Promise<void> => {
  loading.value = true
  loginStore.login(form).then(() => {
    loading.value = false
    // router.push('/')
  })
}
</script>
<template>
  <div class="login-box">
    <div class="form">
      <el-card shadow="always">
        <div class="item">
          <div class="tilte">
            <span>{{ title }}</span>
          </div>
        </div>
        <div class="item">
          <el-input
            v-model="form.userName"
            placeholder="用户名"
            :prefix-icon="UserFilled"
            size="large"
          />
        </div>
        <div class="item">
          <el-input
            v-model="form.userPassword"
            type="password"
            placeholder="密码"
            show-password
            :prefix-icon="Lock"
            size="large"
          />
        </div>
        <div class="item">
          <el-button
            type="primary"
            size="large"
            :loading="loading"
            @click="handleLogin"
            >登录</el-button
          >
        </div>
        <div class="test">测试账号密码：admin/123456</div>
      </el-card>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.login-box {
  display: flex;
  flex-direction: row;
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
  // background-color: green;
  background: url('/images/login-bg.jpeg') no-repeat center center;
  background-size: 100% 100%;
  border-radius: 5px;
  .form {
    width: 550px;
    height: 400px;
    align-items: center;
    align-content: center;
    text-align: center;
    .el-card {
      height: 100%;
      border-radius: 20px;
    }
    .item {
      margin: 20px 0;
    }
    .el-button {
      width: 100%;
    }
    .tilte {
      font-size: 30px;
      margin-bottom: 60px;
    }
    .test {
      color: gray;
      text-align: left;
    }
  }
}
</style>
